package com.hiro.framework.tilegame.controller;

import javax.swing.JOptionPane;

import com.egghiro.framework.j2se.game.core.SGSystem;
import com.hiro.framework.tilegame.controller.system.STileGameSystem;
import com.hiro.framework.tilegame.model.actor.ITileBoard;


public class GameClearState extends GameState {

    private static GameClearState instance;
    private static byte[] lock = new byte[0];

//    private FifteenPuzzleCanvas canvas;
//    private ITiles tiles;

//    private GameClearState( canvas, ITiles tiles) {
//        this.canvas = canvas;
//        this.tiles = tiles;
//    }
    
    private GameClearState(ITileBoard tiles) {
        super(tiles);
    }

    public static GameClearState getInstance(ITileBoard tiles) {
        if (instance == null || instance.equals(tiles) == false) {
            synchronized (lock) {
                if (instance == null || instance.equals(tiles) == false) {
                    instance = new GameClearState(tiles);
                }
            }
        }
        return instance;
    }

    public void showClearDialog() {
        switch ( STileGameSystem.getInstance().showMessage("Clear!!\nOne more Game?", "Clear!!", JOptionPane.OK_CANCEL_OPTION)) {
        case JOptionPane.OK_OPTION:
//            canvas.setState(GameStartState.getInstance(canvas, tiles));
            STileGameSystem.getInstance().restart();
            break;
        default:
            SGSystem.exit();
            break;
        }
    }
}
